var express = require('express');
var router = express.Router();
const userController = require('../controllers/userController')
const interviewsController = require('../controllers/interviewsController')
const uploadfileController = require('../controllers/uploadfileController')
const multer = require('multer')

//配置上传目录
// 改成自定义文件名
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, 'uploads/')
  },
  filename: function (req, file, cb) {
    // 例：用时间戳+原始文件名，防止重名
    const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9)
    cb(null, uniqueSuffix + '-' + file.originalname)
  }
})
const uploadDir = multer({ storage: storage })

/* GET users listing. */
router.get('/', function (req, res, next) {
  res.send('respond with a resource');
});

// 注册
router.post('/register', userController.register)

// 登录
router.post('/login', userController.login)

//上传公司文件
router.post('/upload', uploadDir.single('file'), uploadfileController.upload)

//上传个人简历
router.post('/uploadResume', uploadDir.single('file'), uploadfileController.uploadResume)

// 获取用户已投递的岗位
router.get('/getPosition', userController.getPosition)

//获取公司详情
router.get('/getCompanyDetail', userController.getCompanyDetail)

// 创建面试管理接口
router.post('/postInterview', interviewsController.postInterview)

// 向ai获取面试问题接口(弃用)
router.post('/getQuestion', interviewsController.getQuestion)

// 向后端提交用户回答接口（供ai调用）
router.post('/answer', interviewsController.answer)

// 获取自己面试问题接口（复盘用）
router.get('/getMyQuestion', interviewsController.getMyQuestion)

// 获取自己面试答案接口（复盘用）
router.get('/getMyAnswer', interviewsController.getMyAnswer)

//开始面试接口（生成问题）
router.post('/startInterview', interviewsController.startInterview);

//生成后续面试问题接口
router.post('/followupQuestion', interviewsController.followupQuestion);

// 评估分数
router.post('/getScore', interviewsController.getScore)

// 获取已经投递（未面试）岗位
router.get('/Positions', userController.Positions)

// 获取评估分数(面试复盘用)
router.get('/MyScore', userController.MyScore)

module.exports = router;
